<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="/Public/js/three.min.js"></script>
    <script src="/Public/js/OrbitControls.js"></script>
    <script src="/Public/js/jquery-3.7.1.min.js"></script>
    <script src="/Public/js/geotiff.js"></script>
    <script src="/Public/js/f3d.js"></script>
    <style>
        body {
            margin: 0;
            overflow: hidden;
            background: #1a1a2e;
            font-family: Arial, sans-serif;
        }
    </style>

</head>

<body>
    <script>
        let terrainMesh = null;
        let heightScale = 0.5;
        let smoothness = 3;

        const scene = new THREE.Scene();
        scene.background = new THREE.Color(0x1a1a2e);

        // 创建相机
        const camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 0.1, 10000);
        camera.position.set(1, 10, 3);

        // 创建渲染器
        const renderer = new THREE.WebGLRenderer({ antialias: true });
        renderer.setSize(window.innerWidth, window.innerHeight);
        document.body.appendChild(renderer.domElement);

        // 添加光源
        const ambientLight = new THREE.AmbientLight(0x404040);
        scene.add(ambientLight);
        const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
        directionalLight.position.set(1, 1, 1);
        scene.add(directionalLight);
        // 添加控制器
        const controls = new THREE.OrbitControls(camera, renderer.domElement);
        controls.enableDamping = true;

        //-------------------------------------

        // 启用裁剪
        renderer.localClippingEnabled = true;

        const planeGeometry = new THREE.PlaneGeometry(5, 5);

        // 左侧平面（蓝色）
        const leftPlane = new THREE.Mesh(planeGeometry, new THREE.MeshBasicMaterial({
            color: '#3f7b9d',
            side: THREE.DoubleSide,
            clippingPlanes: [
                new THREE.Plane(new THREE.Vector3(-1, 0, 0), 0) // 保留左侧
            ]
        }));
        leftPlane.rotateX(-Math.PI / 2);
        leftPlane.position.set(-2.5, 0, 0); // 向左移动
        scene.add(leftPlane);

        // 右侧平面（红色）
        const rightPlane = new THREE.Mesh(planeGeometry, new THREE.MeshBasicMaterial({
            color: '#ff0000',
            side: THREE.DoubleSide,
            clippingPlanes: [
                new THREE.Plane(new THREE.Vector3(1, 0, 0), 0) // 保留右侧
            ]
        }));
        rightPlane.rotateX(-Math.PI / 2);
        rightPlane.position.set(2.5, 0, 0); // 向右移动
        scene.add(rightPlane);

        // 显示原始完整平面作为参考（灰色）
        const fullPlane = new THREE.Mesh(planeGeometry, new THREE.MeshBasicMaterial({
            color: '#666666',
            side: THREE.DoubleSide,
            wireframe: true
        }));
        fullPlane.rotateX(-Math.PI / 2);
        fullPlane.position.set(0, 0.1, 0); // 稍微抬高避免重叠
        scene.add(fullPlane);



        //-------------------------------------


        // 动画循环
        function animate() {
            requestAnimationFrame(animate);
            controls.update();
            renderer.render(scene, camera);
        }
        animate();


    </script>
</body>

</html>